﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.IO;


namespace QLKS.ViewModels
{
    static public class ExcelImportViewModel
    {
        static public DataTable Import()
        {
            DataTable tb = new DataTable();
            Microsoft.Win32.OpenFileDialog OpentDialog = new Microsoft.Win32.OpenFileDialog() 
            {
                Multiselect = false,
                Filter = "Excel filter|*.xls"
            };
            OpentDialog.ShowDialog();
            if (OpentDialog.FileName == string.Empty)
                return tb;
            System.IO.FileInfo file = new System.IO.FileInfo(OpentDialog.FileName);
            if (file == null)
                return tb;
            if (file.Extension == ".xls")
            {
                try
                {
                    tb = Models.XlsProvider.GetDataFromExcel(file.FullName);
                }
                catch
                {
                    MessageBox.Show(SysLib.LanguageLib.GetLanguage().Equals("V")?"Import Excel thất bại!":
                        "Import Excel Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return tb;
                }
            }
            else
            {
                MessageBox.Show(SysLib.LanguageLib.GetLanguage().Equals("V")?"File không đúng định dạnh(chỉ hổ trợ .XLS)":
                    "File not match extension (only support .XLS)","error",MessageBoxButton.OK,MessageBoxImage.Error);
                return tb;
            }
            return tb;
        }
    }
}
